package cn.zwk.drawing.domain.execution.service;

import cn.zwk.drawing.domain.execution.model.ExecutionRequest;
import cn.zwk.drawing.domain.execution.model.ExecutionResult;
import cn.zwk.drawing.domain.diagram.model.NodeCapability;

import java.util.List;
import java.util.Optional;

/**
 * 脚本执行领域服务接口
 */
public interface ExecutionDomainService {
    
    /**
     * 同步执行脚本
     */
    ExecutionResult executeScript(ExecutionRequest request);
    
    /**
     * 异步执行脚本
     */
    String executeScriptAsync(ExecutionRequest request);
    
    /**
     * 获取异步执行结果
     */
    Optional<ExecutionResult> getExecutionResult(String executionId);
    
    /**
     * 取消执行
     */
    boolean cancelExecution(String executionId);
    
    /**
     * 获取执行历史
     */
    List<ExecutionResult> getExecutionHistory(String nodeId, int limit);
    
    /**
     * 验证执行权限
     */
    boolean validateExecutionPermission(String userId, NodeCapability capability);
    
    /**
     * 获取正在执行的任务
     */
    List<ExecutionResult> getRunningExecutions();
    
    /**
     * 清理已完成的执行记录
     */
    void cleanupCompletedExecutions();
    
    /**
     * 获取执行统计信息
     */
    ExecutionStatistics getExecutionStatistics();
    
    /**
     * 执行统计信息
     */
    record ExecutionStatistics(
        long totalExecutions,
        long successfulExecutions,
        long failedExecutions,
        long averageDuration,
        long currentRunning
    ) {}
}